apiready = function() {
    seajs.use(['../../V', "../../api", "../../jquery", "../../app", "../../service", '../../pop'], function(V, $api, $, $app, service, $pop) {
      $app.ready();
        var vm = {
            el: '.container',
            data: {
                list: [],
                order_states: '7,8,9,10',
                page: 1,
                have_data: true,
                isShowOrderNull: false
            },
            methods: {
                init: function() {
                    if (this.have_data) {
                        this.getList();
                    }
                },
                getList: function() {
                    var unionid = $api.getStorage("shop_unionid");
                    var self = this;
                    $app.ajax(service.buyGetOrderList, {
                        data: {
                            values: {
                                unionid: unionid,
                                order_states: self.order_states,
                                page: self.page
                            }
                        }
                    }, function(res) {
                        console.log("afterOrder: " + JSON.stringify(res));
                        if (res.code == 0) {
                            if (res.data.length > 0 && Array.isArray(res.data)) {
                                var data = res.data;
                                for (var i = 0; i < data.length; i++) {
                                    self.list.push(data[i]);
                                }
                                self.page++;
                            }
                            self.have_data = res.data.length <= 0 ? false : true;
                            self.isShowOrderNull = self.list.length <= 0 ? true : false;
                            // document.querySelector("#orderMyNull").style.display = self.list.length <= 0 ? "block" : "none";
                        }
                    });
                },
                //--查看物流
                delayReceipt: function(et) {
                    var order_id = +et.currentTarget.parentNode.dataset.orderid;
                    $app.openWin("buyViewFlow", {
                        order_id: order_id
                    });
                },
                //--去订单详情
                goOrderDetail: function(et) {
                    var order_id = et.currentTarget.dataset.orderid;
                    var is_group = et.currentTarget.dataset.group == '1' ? true : false;
                    $app.openWin('buyOrderDetail', {
                        order_id: order_id,
                        is_group: is_group,
                        name: api.pageParam.name
                    });
                },
                //--去退款详情
                refundDetail: function(et) {
                    var order_id = +et.currentTarget.parentNode.dataset.orderid;
                    var is_group = et.currentTarget.parentNode.dataset.group == '1' ? true : false;
                    var order_return_id = et.currentTarget.dataset.id;
                    $app.openWin("buyRefundDetail", {
                        order_return_id: order_return_id,
                        order_id: order_id,
                        name: api.pageParam.name
                    });
                },
                //--删除订单
                deleteOrder: function(et) {
                    var unionid = $api.getStorage("shop_unionid");
                    var self = this;
                    var order_id = +et.currentTarget.parentNode.dataset.orderid;
                    var index = +et.currentTarget.dataset.index;
                    var is_group = et.currentTarget.parentNode.dataset.group == '1' ? true : false;
                    var btnStyle = ['', 'background: #A46EFA;color: #fff;'];
                    $pop.msg({
                        title: '温馨提示',
                        msg: '确认要删除订单吗？',
                        btns: ['取消', '删除'],
                        btnStyle: btnStyle
                    }, function(res) {
                        if (res.index == 1) {
                            $app.ajax(service.buyDelOrder, {
                                data: {
                                    values: {
                                        unionid: unionid,
                                        order_id: order_id
                                    }
                                }
                            }, function(res) {
                                //console.log("buyDelOrder: "+JSON.stringify(res));
                                if (res.code == 0) {
                                    self.list.splice(index, 1);
                                    self.have_data = true;
                                    //self.page = 1;
                                    //self.init();
                                    $pop.tip("订单删除成功!");
                                } else {
                                    $pop.tip("删除失败!");
                                }
                            });
                        }
                    });
                }
            },
            mounted: function() {
                var self = this;
                //--撤销申请，返回列表
                api.addEventListener({
                    name: 'refundRepeal_'
                }, function(ret, err) {
                    self.page = 1;
                    self.list = [];
                    self.init();
                });
            },
            created: function() {
                this.init();
            }
        };
        //var shopVue = new Vue(vm);
        var even = function() {

        };
        var newVue = new Vue(vm);
        even();

    })
}
